#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "palmdll.h"
#include <dirent.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <math.h>
#include "palmdll_yjy.h"

using namespace std;
using namespace cv;

int main(int argc, char **argv)
{
    const string dir = "/home/yjy/dataset/palmprint_dectection_tongji/LHand/palmprint_HITsz_format/";
    int total_count = 0, failed_count = 0;
    string filename;
    dirent *file;
    DIR *m_dir = opendir(dir.c_str());

    while ((file = readdir(m_dir)) != NULL)
    {
        if (strcmp(file->d_name, ".") == 0 ||
            strcmp(file->d_name, "..") == 0)
            continue;
        total_count++;
        filename = file->d_name;

        IplImage *imgInput1 = cvLoadImage((dir + filename).c_str(), 0); //加载图像,gray模式
        if (imgInput1 == NULL)
        {
            cout << "Load Image error!" << endl;
            exit(0);
        }
        IplImage *imgInput2 = adjustRotation(imgInput1); //旋转矫正

        IplImage *roi = getROI(imgInput2, false);
        if (roi == NULL)
        {
            cout << "roi extraction error!" << endl;
            failed_count++;
        }
        else
        {
            cvReleaseImage(&roi);
            //cvWaitKey(0);
        }
        cvReleaseImage(&imgInput1);
    }

    cout << "failed_rate=" << failed_count / (float)total_count << endl;
    return 0;
}